define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/orderlist/index',
                    add_url: '',
                    edit_url: '',
                    del_url: '',
                    multi_url: '',
                    table: 'page',
                }
            });

            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                columns: [
                    [
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'user_name', title: __('Username'),operate: 'LIKE %...%', placeholder: '模糊搜索，*表示任意字符', style: 'width:200px'},
                        {field: 'address', title: __('address'),operate: 'LIKE %...%', placeholder: '模糊搜索，*表示任意字符', style: 'width:200px'},
                        //启用时间段搜索
                        {field: 'begintime', title: __('begintime'),  operate: 'BETWEEN', type: 'datetime', addclass: 'datetimepicker', data: 'data-date-format="YYYY-MM-DD"'},
                        {field: 'server_days_id', title: __('serverdays'),
                            searchList: {'14':'14天', '26': '26天', '42': '42天', '52': '52天'}},
                        {field: 'stafftype.zn_value', title: __('意向类型'),operate: 'LIKE %...%', placeholder: '模糊搜索，*表示任意字符', style: 'width:200px'},
                        {field: 'staff.id', title: __('意向员工ID'),operate: 'LIKE %...%', placeholder: '模糊搜索，*表示任意字符', style: 'width:200px'},
                        {field: 'staff.name', title: __('意向员工名字'),operate: 'LIKE %...%', placeholder: '模糊搜索，*表示任意字符', style: 'width:200px'},
                        {field: 'status', title: __('Status'),  formatter: Table.api.formatter.status1,
                            searchList: {'0':'未分配', '1': '已分配', '2': '取消订单', '3': '面试中', '4': '面试失败'}},
                        {field: 'operate', title: __('Operate'),  events: Controller.api.events.operate, formatter: Controller.api.formatter.operate}
                    ]
                ],
                //普通搜索
                commonSearch: true,
                searchFormVisible: true,
                titleForm: '', //为空则不显示标题，不定义默认显示：普通搜索
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        addinterview: function () {
            Controller.api.bindevent();
        },

        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {
                operate: function (value, row, index) {
                    //返回字符串加上Table.api.formatter.operate的结果
                    //默认需要按需显示排序/编辑/删除按钮,则需要在Table.api.formatter.operate将table传入
                    //传入了table以后如果edit_url为空则不显示编辑按钮,如果del_url为空则不显显删除按钮
                    var result='<a class="btn btn-info btn-xs btn-facelist"><i class="fa fa-user"></i> ' + '面试列表' + '</a> '+
                        Table.api.formatter.operate(value, row, index, $("#table"))
                    if (row.status === 0) {
                        return '<a class="btn btn-info btn-xs btn-detail"><i class="fa fa-user"></i> ' + '分配' + '</a> '
                            + result;
                    }
                    else if (row.status === 4) {
                        return '<a class="btn btn-info btn-xs btn-detail"><i class="fa fa-user"></i> ' + '重分配' + '</a> '
                            + result;
                    }
                    else{
                        return result;
                    }
                },
            },
            events: {
                operate: $.extend({
                   'click .btn-detail': function (e, value, row, index) {
                      /* $.ajax({
                            url:"",
                           data:"",
                           dataType:"json",
                           type:"get",
                           success:function () {
                           }
                       });*/
                       var table = $("#table");
                       Backend.api.open('order/stafflist/index'+'?orderid='+row['id'], '分配订单,显示可用员工');
                    },
                    'click .btn-facelist': function (e, value, row, index) {
                        /* $.ajax({
                              url:"",
                             data:"",
                             dataType:"json",
                             type:"get",
                             success:function () {
                             }
                         });*/
                        var table = $("#table");
                        Backend.api.open('order/myinterview/index'+'?orderid='+row['id'], '面试列表');
                    }
                })
            }
        }
    };
    return Controller;
});